import dao.IUserDao;
import domain.User;
import mybatis.io.Resources;
import mybatis.sqlsession.SqlSession;
import mybatis.sqlsession.SqlSessionFactory;
import mybatis.sqlsession.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class ApplicationContext {
    public static void main(String[] args) throws IOException {
        final InputStream in = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        final SqlSessionFactory factory = builder.build(in);
        final SqlSession session = factory.openSession();
        final IUserDao mapper = session.getMapper(IUserDao.class);
        final List<User> users = mapper.findAll();
        users.forEach(System.out::println);
        session.close();
        in.close();
    }
}
